<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps({
  rate: {
    type: Number,
    default: 0,
  },
})

const rateCSS = computed(() => `${-128 + props.rate * 100}%`)
</script>

<template>
  <div class="flask">
    <div class="label">{{ props.rate.toFixed(2) }}</div>
    <div class="water">
      <svg
        xmlns="http://www.w3.org/2000/svg"
        version="1.0"
        viewBox="0 0 600 140"
        class="wave"
      >
        <path
          d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z"
        ></path>
      </svg>
      <svg
        xmlns="http://www.w3.org/2000/svg"
        version="1.0"
        viewBox="0 0 600 140"
        class="wave"
      >
        <path
          d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z"
        ></path>
      </svg>
      <svg
        xmlns="http://www.w3.org/2000/svg"
        version="1.0"
        viewBox="0 0 600 140"
        class="wave"
      >
        <path
          d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z"
        ></path>
      </svg>
    </div>
  </div>
</template>

<style>
.flask {
  position: relative;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 2px 7px 0 #238fdb;
  background-image: linear-gradient(#021f40, #021f40),
    linear-gradient(180deg, rgba(36, 144, 220, 0.41), rgba(37, 147, 225, 1));
  background-origin: border-box;
  background-clip: content-box, border-box;
  overflow: hidden;
}

.label {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 4;
  color: #fff;
  font-size: 3rem;
  font-family: 'Times New Roman', Times, serif;
  text-align: center;
  align-content: center;
}

.water {
  position: absolute;
  width: 100%;
  height: 100%;
  bottom: v-bind(rateCSS);
  background-color: #a0edff;
}

.wave {
  position: absolute;
  bottom: 100%;
  width: 200%;
  margin-bottom: -2px;
}

.wave:nth-child(1) {
  fill: #a0edff;
  transform: translate(-50%, 0);
  z-index: 3;
  animation: wave-move1 1.5s linear infinite;
}

.wave:nth-child(2) {
  fill: rgba(40, 187, 255, 0.5);
  transform: translate(0, 0);
  z-index: 2;
  animation: wave-move2 3s linear infinite;
}

.wave:nth-child(3) {
  fill: #2084cc;
  transform: translate(-50%, 0);
  z-index: 1;
  animation: wave-move1 3s linear infinite;
}

@keyframes wave-move1 {
  100% {
    transform: translate(0, 0);
  }
}

@keyframes wave-move2 {
  100% {
    transform: translate(-50%, 0);
  }
}
</style>
